package com.zzld.modules.sys.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzld.core.service.BaseServiceImpl;
import com.zzld.modules.common.dto.TreeGrid;
import com.zzld.modules.sys.entity.Role;
import com.zzld.modules.sys.mapper.RoleMapper;
import com.zzld.modules.sys.service.IRoleService;

@Service("roleService")
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {

	@Autowired
	private RoleMapper roleMapper;

	
	public List<TreeGrid> treeGridall(){
		List<TreeGrid> treeGrids = new ArrayList<TreeGrid>();
		List<Role> listRes=roleMapper.selectbystuats();
		if(listRes !=null && listRes.size()>0){
			for (Role res : listRes) {
				TreeGrid treeGrid=new TreeGrid();
				BeanUtils.copyProperties(res, treeGrid);
				treeGrid.setText(res.getName());
				treeGrids.add(treeGrid);
			}
		}
		return treeGrids;
	}
	
	/**
	 * 根据id获取树形节点
	 * @param id
	 * @return
	 */
	public List<TreeGrid> treeGridbyid(String id){
		List<TreeGrid> treeGrids = new ArrayList<TreeGrid>();
		List<Role> listRoles = roleMapper.selectbyuserid(id);
		if(listRoles !=null && listRoles.size()>0){
			for (Role res : listRoles) {
				TreeGrid treeGrid=new TreeGrid();
				BeanUtils.copyProperties(res, treeGrid);
				treeGrid.setText(res.getName());
				treeGrids.add(treeGrid);
			}
		}
		return treeGrids;
	}
	
 
	
	public int delcall(String id)throws Exception{
	  try{
		  return (Integer)roleMapper.delcall(id);
	  }catch(Exception e){
		  e.printStackTrace();
	  }
	  return 0;
	}

	/*
	 * 获取数据列表
	 */
	public PageInfo treegrid(Map map,int pageNum,int pageSize) {

		Map<String, Object> params = map;
		// 以name字段升序排序，
		
		PageHelper.startPage(pageNum,pageSize);
		List<Role> list = roleMapper.rolelist(params);
		PageInfo page = new PageInfo(list);

		return  page;
	}

}
